import 'package:sports_new/entity/match/expert_views_entity.dart';

enum PlanPackStatus{
  sale(1),
  close(8),
  complete(9),
  unKnown(0);

  final int status;

  const PlanPackStatus(this.status);

  static PlanPackStatus getStatus(int status){
    switch(status){
      case 1:
        return PlanPackStatus.sale;
      case 8:
        return PlanPackStatus.close;
      case 9:
        return PlanPackStatus.complete;
      default:
        return PlanPackStatus.unKnown;
    }
  }
}

class PlanPackEntity {
  String? expertId;
  String? expertLogo;
  String? expertName;
  String? oldPrice;
  int? packageId;
  String? packageTag;
  String? price;
  int? sportsId;
  String? tag;
  String? title;
  int? isBuy;
  int? isCanBuy;
  String? content;
  List<PlanEntity>? plans;
  int? total;
  List<String>? historyTag;
  PlanPackStatus? status;

  PlanPackEntity(
      {this.expertId,
        this.expertLogo,
        this.expertName,
        this.oldPrice,
        this.packageId,
        this.price,
        this.sportsId,
        this.tag,
        this.title,
        this.isBuy,
        this.content,
        this.plans,
        this.total,
        this.historyTag,
        this.status
      });

  PlanPackEntity.fromJson(Map<String, dynamic> json) {
    expertId = json['expertId'];
    expertLogo = json['expertLogo'];
    expertName = json['expertName'];
    oldPrice = json['oldPrice'];
    packageId = json['packageId'];
    packageTag = json['packageTag'];
    price = json['price'];
    sportsId = json['sportsId'];
    tag = json['tag'];
    title = json['title'];
    isBuy = json['isBuy'];
    isCanBuy = json['isPossibleBuy'];
    content = json['content'];
    if (json['plans'] != null) {
      plans = [];
      json['plans'].forEach((v) {
        plans!.add(new PlanEntity.fromJson(v));
      });
    }
    total = json['total'];
    if (json['history'] != null) {
      historyTag = [];
      json['history'].forEach((v) {
        historyTag!.add(v);
      });
    }
    if(json['status']!=null)
    status = PlanPackStatus.getStatus(json['status']??0);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['expertId'] = this.expertId;
    data['expertLogo'] = this.expertLogo;
    data['expertName'] = this.expertName;
    data['oldPrice'] = this.oldPrice;
    data['packageId'] = this.packageId;
    data['packageTag'] = this.packageTag;
    data['price'] = this.price;
    data['sportsId'] = this.sportsId;
    data['tag'] = this.tag;
    data['title'] = this.title;
    data['isBuy'] = this.isBuy;
    data['isPossibleBuy'] = this.isCanBuy;
    data['content'] = this.content;
    if (this.plans != null) {
      data['plans'] = this.plans!.map((v) => v.toJson()).toList();
    }
    data['total'] = this.total;
    if (this.historyTag != null) {
      data['history'] = this.historyTag!.map((v) => v).toList();
    }
    data['status'] = this.status?.status;
    return data;
  }

  bool get showPay{
    return (status == PlanPackStatus.sale || status == PlanPackStatus.close) && isBuy == 0;
  }
}